package mystack;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 155 最小栈
 */
public class MinStack {
    Deque<Integer> stack;
    Deque<Integer> minStack;

    public MinStack() {
        stack=new LinkedList<>();
        minStack=new LinkedList<>();
        minStack.push(Integer.MAX_VALUE);
    }
    public void push(int val){
        stack.push(val);
        minStack.push(Math.min(minStack.peek(),val));
    }
    public void pop(){
        stack.pop();
        minStack.pop();
    }
    public int top(){
        return stack.peek();
    }
    public int getMin(){
        return minStack.peek();
    }

    public static void main(String[] args) {
        MinStack stack = new MinStack();
        stack.push(-2);
        stack.push(0);
        stack.push(-3);
        int min = stack.getMin();//-3
        System.out.println(min);
        stack.pop();
        int top = stack.top();//0
        System.out.println(top);
        int min1 = stack.getMin();//-2
        System.out.println(min1);
    }
}
